<%-- 
Document   : viewcart
Created on : Sep 17, 2011, 12:38:11 PM
Author     : Monkey
--%>
<%@page import="java.net.URL"%>
<%@page import="java.io.File"%>
<%@page import="org.apache.jasper.tagplugins.jstl.core.Url"%>
<%@page import="Assignment.BLO.BookBLO"%>
<%@page import="Assignment.BLO.UserBLO"%>
<%@page import="java.io.InputStream"%>
<%@page import="java.util.Properties"%>
<%@page import="Assignment.Util.ConnectionUtil"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="Controller.*" %>
<%@page import="java.util.*" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Awesomebooks.com - View your Cart</title>
        <link href="css/style.css" rel="stylesheet" type="text/css"/>
        <link href="css/bannerstyle.css" rel="stylesheet" type="text/css"/>
        <link href="css/TableCSS.css" rel="stylesheet" type="text/css"/>
        <link href="css/thumbnail_css.css" rel="stylesheet" type="text/css"/>

        <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />

        <script type="text/javascript">
            function setVisibility(showUser){
                if(showUser == "true"){
                    document.getElementById("user").style.visibility = "visible";
                    document.getElementById("loggeduser").style.visibility = "hidden";
                }else{
                    document.getElementById("loggeduser").style.visibility = "visible";
                    document.getElementById("user").style.visibility = "hidden";
                }
            }

            function checkSearch(){
                if (document.getElementById("searchText").value.toString().length == 0){
                    alert("Must input somrthing!")
                    return false;
                }else{
                    return true;
                }
            }

            function checkRemove() {
                var result = false;
                var list =  document.getElementsByName("cBox");
                for (i=0; i<list.length; i++) {
                    if (list[i].checked) {
                        return true;
                    } else {
                        result = false;
                    }
                }
                return result;
            }
        </script>
        <%
                    //check and set username
                    String loggedUser = (String) session.getAttribute("USER");
                    String showUser = "";
                    if (loggedUser == null) {
                        showUser = "true";
                    } else {
                        showUser = "false";
                    }
        %>
    </head>
     <body onload='setVisibility("<%=showUser%>")'>
        <c:import var="bookxml" url="${sessionScope.BOOKURL}"/>
        <x:parse var="doc" xml="${bookxml}" scope="session"/>
        <c:import var="newbookxml" url="${sessionScope.NEWBOOKURL}"/>
        <x:parse var="newdoc" xml="${newbookxml}" scope="session"/>
        <c:set var="search" value="${param.searchText}"/>
        <c:set var="doc" value="${sessionScope.doc}" />
        <div id="header-wrap">
            <div id="header">
                <div style="margin:0px; text-align: left; float: left;"> <span style="color: #FFFFFF; font-family:'Arial Black',Gadget,sans-serif; font-size: 20px; font-weight: bold; letter-spacing: -2px;"><a href="index.jsp" style="color: #FFF; text-decoration: none;" title="Awesomebooks.com">AWESOMEBOOKS</a></span> <a style="color: #FFF; font-size: 18px; font-family: Georgia, 'Times New Roman', Times, serif; font-style:italic; font-weight:normal; text-decoration: none;" href="index.jsp" title="Find your own book">Find your own book</a> 	</div>
                <ul class="menu">

                    <!-- Begin Simple Item Without Drop -->
                    <li class="">
                        <a href="newrelease.jsp">New Release</a>
                    </li>
                    <li class="">
                        <a href="bestseller.jsp">Best Seller</a>
                    </li>
                    <li class="">
                        <a href="bookreview.jsp">Books Review</a>
                    </li>

                    <li class="drop">
                        <a href="#">Catalogs</a>
                        <span class="toggle">&nbsp;</span>
                        <ul>
                            <li><a href="Controller?Action=Search&searchText=literature&Category=true">Literature</a></li>
                            <li><a href="Controller?Action=Search&searchText=life style&Category=true">Life Style</a></li>
                            <li><a href="Controller?Action=Search&searchText=tutorial&Category=true">Tutorial</a></li>
                            <li><a href="Controller?Action=Search&searchText=discovery&Category=true">Discovery</a></li>
                            <li><a href="Controller?Action=Search&searchText=science&Category=true">Science</a></li>
                            <li><a href="Controller?Action=Search&searchText=kids&Category=true">Kids</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
            <div id="underheader">
                <form action="Controller" onsubmit="return checkSearch()" method="POST">
                    <span id="searchbox" style="width:50%">
                        <input id="searchText" name="searchText" type="text" style="width:250px; border:1px solid #333333" />
                        <input name="Action" type="submit" value="Search" id="button" />
                    </span>
                    <span id="user" style="width:25%">
                        <a href="login.jsp">Login</a> |
                        <a href="register.jsp">Register</a>
                    </span>
                    <span id="loggeduser" style="width:25%;position: relative; left: -180px; visibility: hidden">
                        <a><%=loggedUser%></a>
                        <a href="Controller?Action=Logout">(Logout)</a>
                        <a id="user_link" href="viewcart.jsp">| View Cart</a>
                    </span>
                </form>
            </div>
        </div>
        <center>
           <div id="content-header" style="height: 50px">
                <ul>
                    <a>BOOKS IN YOUR CART</a>
                </ul>
            </div>
            <form action="Controller" method="POST" id="content" style="position: relative; left: 0px;">
        <%
                    CartList list = (CartList) session.getAttribute("cart");
                    if (list == null || list.getList().isEmpty()) {

        %>
        <br/><div id="nobookwarning">No book has been added yet, back to <a href="index.jsp" style="text-decoration: blink; color: white">home</a> to find one</div><br/>
        <div style="background-color: #333333; width: 100%; height: 12px"></div>
        <%                            } else {

                                ArrayList<CartBean> ar = list.getList();
                                if (ar.size() > 0) {
        %>
            <br/>
            <table style="width: 95%" >
                <thead style="height: 40px;background-color: #333333; color: white">
                    <tr>
                        <th  style="width: 10%">No.</th>
                        <th  style="width: 55%">Title</th>
                        <th  style="width: 10%">Quantity</th>
                        <th  style="width: 15%">Price</th>
                        <th  style="width: 10%">Remove</th>
                    </tr>
                </thead>
                <tbody>
                    <%
                                                        int count = 0;
                                                        String bookID = "";
                                                        String title = "";
                                                        float price = 0;
                                                        float total = (float) 0;
                                                        for (int i = 0; i < ar.size(); i++) {
                                                            bookID = ar.get(i).getBookID();
                                                            int quantity = ar.get(i).getQuantity();
                    %>
                    <c:set var="bookID" value="<%=bookID%>" />
                    <c:set var="quantity" value="<%=quantity%>" />
                    <x:set var="price" select="$doc//*[bookID=$bookID]/price/text()*$quantity" />
                    <%
                                                            price = Float.parseFloat(pageContext.getAttribute("price") + "");
                                                            total += price;
                    %>
                    <tr style="background-color: #C0C0C0; color: #666666">
                        <td style="height: 50px; width: 10%"><%=++count%></td>
                        <td style="height: 50px; width: 55%"><x:out select="$doc//*[bookID=$bookID]/title" /></td>
                        <td style="height: 50px; width: 10%"><%=quantity%></td>
                        <td style="height: 50px; width: 15%"><c:out value="${price}" /></td>
                        <td style="height: 50px; width: 10%"><input type="checkbox" name="cBox" value="<%=bookID%>" /></td>
                    </tr>
                    <%
                                                        }
                    %>
                    <input type="hidden" name="hidTotal" id="hidTotal" value="<%=total%>" />
                    <tr style="background-color: #666666; color: #FFFFFF">
                        <td colspan="3" align="right" style="height: 30px; text-align: right">Total:</td>
                        <td colspan="1" style="height: 30px"><%=total%></td>
                        <td colspan="1" style="height: 30px"><input type="submit" value="RemoveCart" name="Action" id="button" onclick="return checkRemove();" /></td>
                    </tr>
                    <%

                                            }
                    %>

                    <tr style="background-color: #E0E0E0; color: #333333">
                        <td style="height: 30px"></td>
                        <td  style="height: 30px"></td>
                        <td style="height: 30px" colspan="3"><input type="submit" value="CheckOut" name="Action" id="button"/></td>
                    </tr>
                    <tr>
                        <td colspan="5" style="height: 50px"><a href="Controller?Action=AddMore" style="text-decoration: blink; color: white">Looking for more awesome books?</a></td>
                    </tr>
                    <tr style="background-color: #333333">
                        <td colspan="5" style="height: 20px"></td>
                    </tr>
                </tbody>
            </table>
             
        <%
                    }
        %>

            </form>
        </center>
        
    </body>
</html>
